home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kabc / address.h next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  8.6 KB  |  342 lines

  1. /*
  2.     This file is part of libkabc.
  3.     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.     Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef KABC_ADDRESS_H
  22. #define KABC_ADDRESS_H
  23.  
  24. #include <qmap.h>
  25. #include <qstring.h>
  26. #include <qvaluelist.h>
  27.  
  28. #include <kdelibs_export.h>
  29.  
  30. // template tags for address formatting localization
  31. #define KABC_FMTTAG_realname   QString("%n")
  32. #define KABC_FMTTAG_REALNAME   QString("%N")
  33. #define KABC_FMTTAG_company    QString("%cm")
  34. #define KABC_FMTTAG_COMPANY    QString("%CM")
  35. #define KABC_FMTTAG_pobox      QString("%p")
  36. #define KABC_FMTTAG_street     QString("%s")
  37. #define KABC_FMTTAG_STREET     QString("%S")
  38. #define KABC_FMTTAG_zipcode    QString("%z")
  39. #define KABC_FMTTAG_location   QString("%l")
  40. #define KABC_FMTTAG_LOCATION   QString("%L")
  41. #define KABC_FMTTAG_region     QString("%r")
  42. #define KABC_FMTTAG_REGION     QString("%R")
  43. #define KABC_FMTTAG_newline    QString("\\n")
  44. #define KABC_FMTTAG_condcomma  QString("%,")
  45. #define KABC_FMTTAG_condwhite  QString("%w")
  46. #define KABC_FMTTAG_purgeempty QString("%0")
  47.  
  48. namespace KABC {
  49.  
  50. /**
  51.   @short Postal address information.
  52.   
  53.   This class represents information about a postal address.
  54. */
  55. class KABC_EXPORT Address
  56. {
  57.     friend KABC_EXPORT QDataStream &operator<<( QDataStream &, const Address & );
  58.     friend KABC_EXPORT QDataStream &operator>>( QDataStream &, Address & );
  59.  
  60.   public:
  61.     /**
  62.       List of addresses.
  63.     */
  64.     typedef QValueList<Address> List;
  65.     typedef QValueList<int> TypeList;
  66.   
  67.     /**
  68.       Address types:
  69.      
  70.       @li @p Dom -    domestic
  71.       @li @p Intl -   international
  72.       @li @p Postal - postal
  73.       @li @p Parcel - parcel
  74.       @li @p Home -   home address
  75.       @li @p Work -   address at work
  76.       @li @p Pref -   preferred address
  77.     */
  78.     enum Type { Dom = 1, Intl = 2, Postal = 4, Parcel = 8, Home = 16, Work = 32,
  79.            Pref = 64 };
  80.  
  81.     /**
  82.       Constructor that creates an empty Address, which is initialized
  83.       with a unique id (see id()).
  84.     */
  85.     Address();
  86.   
  87.     /**
  88.       This is like Address() just above, with the difference
  89.       that you can specify the type.
  90.     */
  91.     Address( int );
  92.  
  93.     bool operator==( const Address & ) const;
  94.     bool operator!=( const Address & ) const;
  95.   
  96.     /**
  97.       Returns true, if the address is empty.
  98.     */
  99.     bool isEmpty() const;
  100.  
  101.     /**
  102.       Clears all entries of the address.
  103.     */
  104.     void clear();
  105.  
  106.     /**
  107.       Sets the unique id.
  108.     */
  109.     void setId( const QString & );
  110.  
  111.     /*
  112.       Returns the unique id.
  113.     */
  114.     QString id() const;
  115.  
  116.     /**
  117.       Sets the type of address. See enum for definiton of types. 
  118.      
  119.       @param type type, can be a bitwise or of multiple types.
  120.     */
  121.     void setType( int type );
  122.  
  123.     /**
  124.       Returns the type of address. Can be a bitwise or of multiple types.
  125.     */
  126.     int type() const;
  127.  
  128.     /**
  129.       Returns a translated string of all types the address has.
  130.     */
  131.     QString typeLabel() const;
  132.  
  133.     /**
  134.       Sets the post office box.
  135.     */
  136.     void setPostOfficeBox( const QString & );
  137.  
  138.     /**
  139.       Returns the post office box.
  140.     */
  141.     QString postOfficeBox() const;
  142.  
  143.     /**
  144.       Returns the translated label for post office box field.
  145.     */
  146.     static QString postOfficeBoxLabel();
  147.  
  148.     /**
  149.       Sets the extended address information.
  150.     */
  151.     void setExtended( const QString & );
  152.  
  153.     /**
  154.       Returns the extended address information.
  155.     */
  156.     QString extended() const;
  157.  
  158.     /**
  159.       Returns the translated label for extended field.
  160.     */
  161.     static QString extendedLabel();
  162.     
  163.     /**
  164.       Sets the street (including number).
  165.     */
  166.     void setStreet( const QString & );
  167.  
  168.     /**
  169.       Returns the street.
  170.     */
  171.     QString street() const;
  172.  
  173.     /**
  174.       Returns the translated label for street field.
  175.     */
  176.     static QString streetLabel();
  177.  
  178.     /**
  179.       Sets the locality, e.g. city.
  180.     */
  181.     void setLocality( const QString & );
  182.  
  183.     /**
  184.       Returns the locality.
  185.     */
  186.     QString locality() const;
  187.  
  188.     /**
  189.       Returns the translated label for locality field.
  190.     */
  191.     static QString localityLabel();
  192.  
  193.     /**
  194.       Sets the region, e.g. state.
  195.     */
  196.     void setRegion( const QString & );
  197.  
  198.     /**
  199.       Returns the region.
  200.     */
  201.     QString region() const;
  202.  
  203.     /**
  204.       Returns the translated label for region field.
  205.     */
  206.     static QString regionLabel();
  207.  
  208.     /**
  209.       Sets the postal code.
  210.     */
  211.     void setPostalCode( const QString & );
  212.  
  213.     /**
  214.       Returns the postal code.
  215.     */
  216.     QString postalCode() const;
  217.  
  218.     /**
  219.       Returns the translated label for postal code field.
  220.     */
  221.     static QString postalCodeLabel();
  222.  
  223.     /**
  224.       Sets the country.
  225.     */
  226.     void setCountry( const QString & );
  227.  
  228.     /**
  229.       Returns the country.
  230.     */
  231.     QString country() const;
  232.  
  233.     /**
  234.       Returns the translated label for country field.
  235.     */
  236.     static QString countryLabel();
  237.  
  238.     /**
  239.       Sets the delivery label. This is the literal text to be used as label.
  240.     */
  241.     void setLabel( const QString & );
  242.  
  243.     /**
  244.       Returns the delivery label.
  245.     */
  246.     QString label() const;
  247.  
  248.     /**
  249.       Returns the translated label for delivery label field.
  250.     */
  251.     static QString labelLabel();
  252.  
  253.     /**
  254.       Returns the list of available types.
  255.     */
  256.     static TypeList typeList();
  257.  
  258.     /**
  259.       Returns the translated label for a special type.
  260.     */
  261.     static QString typeLabel( int type );
  262.  
  263.     /**
  264.       Used for debug output.
  265.     */
  266.     void dump() const;
  267.  
  268.     /** 
  269.       Returns this address formatted according to the country-specific
  270.       address formatting rules. The formatting rules applied depend on 
  271.       either the addresses {@link #country country} field, or (if the 
  272.       latter is empty) on the system country setting. If companyName is
  273.       provided, an available business address format will be preferred.
  274.       
  275.       @param realName   the formatted name of the contact
  276.       @param orgaName   the name of the organization or company
  277.       @return           the formatted address (containing newline characters)
  278.     */
  279.     QString formattedAddress( const QString &realName=QString::null
  280.                             , const QString &orgaName=QString::null ) const;
  281.  
  282.     /**
  283.       Returns ISO code for a localized country name. Only localized country
  284.       names will be understood. This might be replaced by a KLocale method in
  285.       the future.
  286.       @param cname  name of the country
  287.       @return       two digit ISO code
  288.     */
  289.     static QString countryToISO( const QString &cname );
  290.  
  291.     /**
  292.       Returns a localized country name for a ISO code. 
  293.       This might be replaced by a KLocale method in the future.
  294.       @param ISOname two digit ISO code
  295.       @return        localized name of the country
  296.       @since 3.2
  297.     */
  298.     static QString ISOtoCountry( const QString &ISOname );
  299.  
  300.   private:
  301.     /** 
  302.       Parses a snippet of an address template
  303.       @param tsection   the template string to be parsed
  304.       @param result     QString reference in which the result will be stored
  305.       @return           true if at least one tag evaluated positively, else false
  306.     */
  307.     bool parseAddressTemplateSection( const QString &tsection
  308.                                     ,       QString &result
  309.                                     , const QString &realName
  310.                                     , const QString &orgaName ) const;
  311.  
  312.     /** 
  313.       Finds the balanced closing bracket starting from the opening bracket at 
  314.       pos in tsection.
  315.       @return  position of closing bracket, -1 for unbalanced brackets
  316.     */
  317.     int  findBalancedBracket( const QString &tsection, int pos ) const;
  318.  
  319.     bool mEmpty;
  320.   
  321.     QString mId;
  322.     int mType;
  323.   
  324.     QString mPostOfficeBox;
  325.     QString mExtended;
  326.     QString mStreet;
  327.     QString mLocality;
  328.     QString mRegion;
  329.     QString mPostalCode;
  330.     QString mCountry;
  331.     QString mLabel;
  332.  
  333.     static QMap<QString, QString> *mISOMap;
  334. };
  335.  
  336. KABC_EXPORT QDataStream &operator<<( QDataStream &, const Address & );
  337. KABC_EXPORT QDataStream &operator>>( QDataStream &, Address & );
  338.  
  339. }
  340.  
  341. #endif
  342.